<template>
  <s-layout id="layout" :title="'回款账户'" navbar="normal" leftIconColor="#333" :autoBack="false" :bgColor="state.bgColor"
    :tabbarshow='false' :titleStyle="{ color: '#333', fontSize: '32rpx' }">
    <view class="call_on list_box" :style="{ paddingTop: (safeAreaInsets?.top + 44) + 'px' }">
      <scroll-view scroll-y class="comprehensive" v-if="list.length" @scrolltolower='listScrolltolower'
        show-scrollbar="true" :refresher-enabled="isOpenRefresh" :refresher-triggered="triggered"
        :refresher-threshold="100" refresher-background="white" @refresherpulling="onPulling"
        @refresherrefresh="onRefresh" @refresherrestore="onRestore" @refresherabort="onAbort" @scroll="onScroll">
        <view class="item_wrap">
          <view class="item" v-for="(item, index) in list" :key="index" @click="lookDetail(item)">
           <view v-if="item.type == 'bank'">
            <view class="flex">
              <image :src="`${baseUrl}` + item.bank.logo" class="bankimg" mode="scaleToFill" />
              <view class="item_left">
                <view class="item_left_box">
                  <view class="title">{{ item.bank.name }}
                    <text >({{ item.card_balance }})</text>
                  </view>
                </view>
                <view class="item_left_box">
                  <text class="namess">{{ item.bank_branch }}</text>
                </view>
                <view class="item_left_box">
                  <text class="cardnum">{{ item.card }}</text>
                </view>
              </view>
            </view>
            <view class="flex">
              <view class="item_left">
                <view class="item_left_box">
                  <text class="cardnum" >持卡人</text>
                  <text class="namess">{{ item.name }}</text>
                </view>
                <view class="item_left_box">
                  <text class="cardnum">手机号</text>
                  <text class="namess">{{ item.mobile }}</text>
                </view>
              </view>
              <view class="item_right" @click="lookDetail(item)">
                <text class="name">查看详情</text>
                <u-icon size="10" name="arrow-right" color="#0038F7"></u-icon>
              </view>
            </view>
          </view>
          <view v-if="item.type == 'alipay'">
            <view class="flex">
              <image :src="`${baseUrl}` + item.bank.logo" class="bankimg" mode="scaleToFill" />
              <view class="item_left">
                <view class="item_left_box">
                  <view class="title">{{ item.bank.name }}</view>
                </view>
              </view>
            </view>
            <view class="flex">
              <view class="item_left">
                <view class="item_left_box">
                  <text class="cardnum" >姓名</text>
                  <text class="namess">{{ item.name }}</text>
                </view>
                <view class="item_left_box">
                  <text class="cardnum">手机号</text>
                  <text class="namess">{{ item.mobile }}</text>
                </view>
              </view>
              <view class="item_right" @click="lookDetail(item)">
                <text class="name">查看详情</text>
                <u-icon size="10" name="arrow-right" color="#0038F7"></u-icon>
              </view>
            </view>
          </view>
        </view>

        </view>
        <!-- 正在加载组件 -->
        <view>
          <s-loadmore-gather :current_page="listPage" :last_page="listlast_page" ref="loadmoreRef"></s-loadmore-gather>
        </view>
      </scroll-view>

      <u-empty v-else mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" text="暂无内容"
        marginTop="50%"></u-empty>
    </view>
  </s-layout>
  <!-- <添加按钮 -->
  <view>
    <s-button @netWork="submitForm" :text="state.text"></s-button>
  </view>
</template>

<script setup>
import { baseUrl } from '@/sheep/config';
import sheep from '@/sheep';
import { onLoad, onShow } from "@dcloudio/uni-app";
import { ref, reactive } from 'vue';
const { safeAreaInsets } = uni.getSystemInfoSync()
const state = ref({
  bgColor: '#fff',
  text: '添加账户',


})
const list = ref([])
const listPage = ref()
const listlast_page = ref();
const listpagenumber = ref(1);
onLoad((options) => {
  list.value = [];
  listpagenumber.value = 1;
  getListDetail()
})


// 1.
const loadmoreRef = ref()
//数据请求

const getListDetail = () => {
  sheep.$api.returned_info.getReturnedInfo().then((res) => {
    list.value = [...list.value, ...res?.data.rows];
    listPage.value = res.data.current_page
    listlast_page.value = res.data.last_page
    let reg = /^(\d{4})\d+(\d{4})$/;
    list.value.forEach((i) => {
      i.card = i.bank_number.replace(reg, "$1 **** **** $2");
      i.card_balance = i.bank_number.substr(-4);
    })
  });
}

//滚动触底
const listScrolltolower = () => {
  loadmoreRef.value.PopupScrolltolower()
  if (listPage.value < listlast_page.value) {
    listpagenumber.value += 1;
  } else {
    return;
  }
  getListDetail();
};
const lookDetail = (item) => {
  console.log(item)
  sheep.$router.go('/subpackage/staff/workbench/returned_info/returned_info_add', {
    ids: item.id,
    type:item.type,
    state: '1'
  });
}
//跳转页面
const submitForm = () => {
  sheep.$router.go('/subpackage/staff/workbench/returned_info/returned_info_add');
}
// 页面下拉刷新
const freshing = ref(false)
const triggered = ref(false)
const isOpenRefresh = ref(true)  // 是否开启下拉
// 自定义下拉刷新控件被下拉
const onPulling = (e) => {
  if (e.detail.deltaY < 0) return  // 防止上滑页面也触发下拉
  triggered.value = true;
}
// 自定义下拉刷新被触发
const onRefresh = () => {
  if (freshing.value) return;
  freshing.value = true;
  setTimeout(() => {
    listpagenumber.value = 1;
    list.value = []
    triggered.value = false;
    freshing.value = false;
    getListDetail();
  }, 500);
}
// 自定义下拉刷新被复位
const onRestore = () => {
  triggered.value = 'restore'; // 需要重置
  // console.log("onRestore");
}
// 自定义下拉刷新被中止
const onAbort = () => {
  // console.log("onAbort");
}
</script>

<style lang="scss" scoped>
@import '../compentns/publiclist.scss';

// 滚动
.comprehensive {
  width: calc(100% - 40rpx);
  background-color: rgba(0, 0, 0, 0);
  margin: 0 20rpx;
  height: 80vh;
}

.item {
  padding-bottom: 10rpx;

  .title {
    height: auto !important;
    margin-bottom: 0 !important;
  }

  .namess {
    color: #999;
    font-weight: 500;
   font-size:$uni-font-size-26;

  }

  .cardnum {
    color: $uni-text-color;
    font-weight: $uni-font-weight;
   font-size:$uni-font-size-26;
    margin-right: 18rpx;
  }
}

.time_money {
  color: #666666;
  font-weight: 500;
 font-size:$uni-font-size-26;
  margin-right: 16rpx;
}

.time_name {
  font-family: PingFangSC;
  color: #FF6600 !important;
  font-weight: 500;
 font-size:$uni-font-size-26;
}

.item_left {
  .item_left_box {
    margin-bottom: 10rpx !important;
  }
}

.flex {
  border-bottom: 1rpx solid #efefef;

  &:last-child {
    border-bottom: none;
  }
}

.item_wrap .item .item_left {
  width: 74% !important;
}

.item_wrap .item .item_right {
  margin-top: 50rpx !important;
}

//银行卡图片
.bankimg {
  width: 50rpx;
  height: 50rpx;
  border-radius: 50%;
  margin: 20rpx 0rpx 0 20rpx;
}
</style>